package com.antmall.prodouct.controller;

import com.antmall.common.entity.PageVO;
import com.antmall.common.entity.ResultWrapper;
import com.antmall.prodouct.bo.ProdouctAddBO;
import com.antmall.prodouct.bo.ProdouctEditBO;
import com.antmall.prodouct.bo.ProdouctQueryBO;
import com.antmall.prodouct.service.ProductService;
import com.antmall.prodouct.vo.ProdouctQueryVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;

@RestController
@RequestMapping("/product")
@Validated
@Api(tags = "商品管理")
public class ProductController {
    @Autowired
    private ProductService productService;

    @ApiOperation("新增")
    @PostMapping("add")
    public void add(@Valid @RequestBody ProdouctAddBO prodouctAddBO) {
        productService.add(prodouctAddBO);
    }

    @ApiOperation("修改")
    @PostMapping("edit")
    public void edit(@Valid @RequestBody ProdouctEditBO prodouctEditBO) {
        productService.edit(prodouctEditBO);
    }

    @ApiOperation("查询")
    @GetMapping("query")
    public PageVO<ProdouctQueryVO> page(ProdouctQueryBO prodouctQueryBO) {
        return productService.page(prodouctQueryBO);
    }

    @ApiOperation("删除")
    @DeleteMapping("delete")
    public void delete(@Valid @RequestBody List<Long> idList) {
        productService.delete(idList);
    }

}
